<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>layout</title>
	<link rel="stylesheet" type="text/css" href="./jquery-easyui-v1.4.4/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="./jquery-easyui-v1.4.4/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="./jquery-easyui-v1.4.4/demo/demo.css">
	<script type="text/javascript" src="./jquery-easyui-v1.4.4/jquery.min.js"></script>
	<script type="text/javascript" src="./jquery-easyui-v1.4.4/jquery.easyui.min.js"></script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:30px;font-size:20px;color:white;background:#cee3ea;">欢迎使用</div>
	<div data-options="iconCls:'icon-redo',region:'west',split:true,title:'导航菜单'" style="width:300px;">
		<div id="xia_accordion" data-options="fit:true,border:false" class="easyui-accordion" style="background:#95B8E7;width:100%;height:100%;">
			<div title="系统管理" data-options="iconCls:'icon-edit'" style="padding: 10px;">
				<a href="https://www.baidu.com" style="margin:30px;padding:20px">系统管理</a>
			</div>

			<div title="产品管理" data-options="iconCls:'icon-edit',selected:true" style="padding: 10px;">
				<a href="https://www.baidu.com">产品管理</a>
			</div>

			<div title="关于" data-options="iconCls:'icon-help'" style="padding: 10px;">
				<a href="https://www.baidu.com">关于</a>
			</div>
		</div>

	</div>
	<div data-options="region:'center'">
		<div class="easyui-tabs" id="xia_tab" data-options="pill:true" style="width: 100%;height: 100%;">
			<div title="主页">这里没有东西</div>
			<div title="产品管理" data-options="selected:true">
				<div id="xia_layout2" class="easyui-layout" style="width: 100%;height: 100%;">
					<div data-options="region:'west',split:true,title:'产品结构树'" style="width:20%;">
						<ul class="easyui-tree">
							<li ">
								<span>产品分类</span>
								<ul>
									<li data-options="state:'closed'">
										<span>园林庭院</span>
										<ul>
											<li>园林庭院1</li>
											<li>园林庭院2</li>
											<li>园林庭院3</li>
										</ul>
									</li>
									<li>
										<span>景观设施</span>
										<ul>
											<li>庭</li>
											<li>阁</li>
										</ul>
									</li>	
									<li data-options="state:'closed'">
										<span>户外家具</span>
										<ul>
											<li>户外家具1</li>
											<li>户外家具2</li>
											<li>户外家具3</li>
										</ul>
									</li>
									<li>休闲家具</li>
								</ul>
							</li>
						</ul>
					</div>
					<div data-options="region:'center'">
						<table id="dg" class="easyui-datagrid" title="产品管理" style="width:700px;height:auto"
								data-options="
									iconCls: 'icon-save',
									singleSelect: true,
									toolbar: '#tb',
									url: 'datagrid_data1.json',
									method: 'get',
									onClickRow: onClickRow
								">
							<thead>
								<tr>
									<th data-options="field:'itemid',width:80">名称</th>
									<th data-options="field:'listprice',width:80,align:'right',editor:{type:'numberbox',options:{precision:1}}">添加日期</th>
									
								</tr>
							</thead>
						</table>
						<div id="tb" style="height:auto">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="accept()">新增</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="reject()">修改</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="getChanges()">删除</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="getChanges()">查找</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="getChanges()">所有</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div data-options="region:'south',split:true" style="padding:10px;background:#cee3ea;height:40px;text-align:center;">
		<strong>EntWebSite ver 1.0</strong>
	</div>
	<script type="text/javascript">
		(function($){
			function getCacheContainer(t){
				var view = $(t).closest('div.datagrid-view');
				var c = view.children('div.datagrid-editor-cache');
				if (!c.length){
					c = $('<div class="datagrid-editor-cache" style="position:absolute;display:none"></div>').appendTo(view);
				}
				return c;
			}
			function getCacheEditor(t, field){
				var c = getCacheContainer(t);
				return c.children('div.datagrid-editor-cache-' + field);
			}
			function setCacheEditor(t, field, editor){
				var c = getCacheContainer(t);
				c.children('div.datagrid-editor-cache-' + field).remove();
				var e = $('<div class="datagrid-editor-cache-' + field + '"></div>').appendTo(c);
				e.append(editor);
			}
			
			var editors = $.fn.datagrid.defaults.editors;
			for(var editor in editors){
				var opts = editors[editor];
				(function(){
					var init = opts.init;
					opts.init = function(container, options){
						var field = $(container).closest('td[field]').attr('field');
						var ed = getCacheEditor(container, field);
						if (ed.length){
							ed.appendTo(container);
							return ed.find('.datagrid-editable-input');
						} else {
							return init(container, options);
						}
					}
				})();
				(function(){
					var destroy = opts.destroy;
					opts.destroy = function(target){
						if ($(target).hasClass('datagrid-editable-input')){
							var field = $(target).closest('td[field]').attr('field');
							setCacheEditor(target, field, $(target).parent().children());
						} else if (destroy){
							destroy(target);
						}
					}
				})();
			}
		})(jQuery);
	</script>
	<script type="text/javascript">
		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#dg').datagrid('validateRow', editIndex)){
				var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'});
				var productname = $(ed.target).combobox('getText');
				$('#dg').datagrid('getRows')[editIndex]['productname'] = productname;
				$('#dg').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}
		function onClickRow(index){
			if (editIndex != index){
				if (endEditing()){
					$('#dg').datagrid('selectRow', index)
							.datagrid('beginEdit', index);
					editIndex = index;
				} else {
					$('#dg').datagrid('selectRow', editIndex);
				}
			}
		}
		function accept(){
			if (endEditing()){
				$('#dg').datagrid('acceptChanges');
			}
		}
		function reject(){
			$('#dg').datagrid('rejectChanges');
			editIndex = undefined;
		}
		function getChanges(){
			var rows = $('#dg').datagrid('getChanges');
			alert(rows.length+' rows are changed!');
		}
	</script>
</body>
</html>